package alg20241129;

public class Text2 {
    public int minCost(int[][] costs) {
        //
        int n = costs.length;
        //1 创建表
        int[] red = new int[n];
        int[] green = new int[n];
        int[] blue = new int[n];
        //2  初始化
        red[0] = costs[0][0];
        green[0] = costs[0][1];
        blue[0] = costs[0][2];
         //3 填表
        for (int i = 1; i < n; i++) {
            red[i] = Math.min(green[i - 1], blue[i - 1]) + costs[i][0];
            green[i] = Math.min(red[i - 1], blue[i - 1]) + costs[i][1];
            blue[i] = Math.min(green[i - 1], red[i - 1]) + costs[i][2];
        }
        //4 返回值
        return Math.min(Math.min(red[n-1], green[n - 1]), blue[n - 1]);

    }
}
